from django.db import models


# Create your models here.
class User(models.Model):
    user_name = models.CharField(max_length=18, unique=True, verbose_name="用户名")
    user_real_name = models.CharField(max_length=6, unique=False, verbose_name="学生姓名", default="")
    user_id = models.CharField(max_length=11, unique=True, verbose_name="学生学号")
    user_psw = models.CharField(max_length=18, unique=False, verbose_name="学生密码")
    user_create_date = models.DateTimeField(auto_now_add=True, verbose_name="注册时间")
    user_email = models.EmailField(verbose_name='邮箱地址', default="")
    thing_finished = models.IntegerField(verbose_name="用户总共创建的事项", default=0)
    thing_all = models.IntegerField(verbose_name="用户已完成的事项", default=0)
    thing_wait = models.IntegerField(verbose_name="用户待完成的事项", default=0)

    def __str__(self):
        return self.user_name

    class Meta:
        ordering = ["-user_create_date"]
        verbose_name = "学生用户"
        verbose_name_plural = "学生用户"


class Schedule(models.Model):
    create_by = models.CharField(max_length=11, verbose_name="创建者")
    create_date = models.DateTimeField(auto_now_add=True)
    title = models.CharField(max_length=48, verbose_name="标题")
    theme = models.CharField(max_length=48, verbose_name="主题", default="学习")
    status = models.CharField(max_length=48, verbose_name="状态", default="未完成")
    alert_mode = models.CharField(max_length=48, verbose_name="提醒方式", default="短信提醒")
    important_level = models.CharField(max_length=48, verbose_name="重要程度", default="一般")
    content = models.CharField(max_length=256, verbose_name="内容")
    start_date = models.DateTimeField(verbose_name="开始时间")
    end_date = models.DateTimeField(verbose_name="结束时间")

    def __str__(self):
        return self.title

    class Meta:
        ordering = ["-create_date"]
        verbose_name = "日程"
        verbose_name_plural = "日程"


class History(models.Model):
    history_key = models.CharField(max_length=18, verbose_name="目标用户")
    happen_date = models.DateTimeField(auto_now_add=True, verbose_name="完成时间")
    thing_finished = models.CharField(max_length=48, verbose_name="完成的事件")
    history_type = models.CharField(max_length=8, default="操作", verbose_name="类型")

    def __str__(self):
        return self.history_key + " 完成 " + self.thing_finished

    class Meta:
        ordering = ['-happen_date']
        verbose_name = "日程历史"
        verbose_name_plural = "日程历史"


class Editor(models.Model):
    type = models.CharField(max_length=4)
    title = models.CharField(max_length=48, verbose_name="标题")
    theme = models.CharField(max_length=48, verbose_name="主题", default="学习")
    status = models.CharField(max_length=48, verbose_name="状态", default="未完成")
    alert_mode = models.CharField(max_length=48, verbose_name="提醒方式", default="短信提醒")
    important_level = models.CharField(max_length=48, verbose_name="重要程度", default="一般")
    content = models.CharField(max_length=256, verbose_name="内容")
    start_date = models.DateTimeField(verbose_name="开始时间")
    end_date = models.DateTimeField(verbose_name="结束时间")

    def __str__(self):
        return self.type
